#!/usr/bin/env python


__author__= 'yingnn'

'''methylation fitting using random forest'''


import sys


if len(sys.argv) < 3:
	print sys.argv[0], "fname.\n"
	exit()

fname=sys.argv[1]
thresh=float(sys.argv[2])
# n_trees=sys.argv[2]
# jobs=int(sys.argv[3])
# n_col_sampling=int(sys.argv[4])

# these modules should have been installed. Or u maybe try setting environment variable "export PYTHONPATH=$PYTHONPATH:/mnt/ilustre/app/medical/tools/py_module"
import pandas as pd
import numpy as np
# import random
# from sklearn.model_selection import cross_val_score
from sklearn.model_selection import train_test_split
# from sklearn.ensemble import AdaBoostClassifier as abc
from sklearn import svm



dat= pd.read_csv(fname)

# dat= dat.transpose()

dat1= dat.dropna(axis=1, how='any')

# --------------------


X_train, X_test, y_train, y_test = train_test_split(dat1.iloc[:, 1:] > thresh, dat1.iloc[:, 0], test_size=0.2, random_state=0)


# clf = svm.SVC(kernel='linear', C=1).fit(X_train, y_train)

# --------------------

# Select the algorithm to either solve the dual or primal optimization problem. Prefer dual=False when n_samples > n_features.
lin_clf = svm.LinearSVC(dual=False, verbose=10).fit(X_train, y_train)
# lin_clf.fit(dat1.iloc[:, 1:], dat1.iloc[:, 0])
# dec = lin_clf.decision_function([[1]])
# dec.shape[1]
pre_score= lin_clf.score(X_test, y_test)

f= open('score_svm.txt', 'a')
f.write("\t".join([str(pre_score), sys.argv[2], fname])+ "\n")
f.close()

